package com.example.demo.vo

import com.example.demo.dbmodels.TProduct
import io.swagger.annotations.ApiModelProperty

class ProductVo {


    @ApiModelProperty(value = "id")
    var id: Int? = null

    @ApiModelProperty(value = "商品名称")
    var title: String? = null

    @ApiModelProperty(value = "图片url")
    var url: String? = null

    @ApiModelProperty(value = "价格")
    var price: Double? = null

    @ApiModelProperty(value = "销量")
    var sales: Int? = null

    @ApiModelProperty(value = "商品简介")
    var Introduction: String? = null

    @ApiModelProperty(value = "规格")
    var specification: String? = null

    @ApiModelProperty(value = "商品类型id")
    var productTypeId: Int? = null


    fun getVo(table: TProduct): ProductVo {
        table.let {
            val data = ProductVo()
            data.id = it.id
            data.Introduction = it.introduction
            data.productTypeId = it.productTypeId
            data.price = it.price
            data.sales = it.sales
            data.specification = it.specification
            data.title = it.title
            data.url = it.url
            return data
        }
    }

    fun getListVo(table: List<TProduct>): List<ProductVo>  {
        table.let {
            val listproductVo = mutableListOf<ProductVo>()
            it.forEach {
                val data = ProductVo()
                data.id = it.id
                data.Introduction = it.introduction
                data.productTypeId = it.productTypeId
                data.price = it.price
                data.sales = it.sales
                data.specification = it.specification
                data.title = it.title
                data.url = it.url
                listproductVo.add(data)
            }
            return listproductVo
        }
    }


}